package com.wayful.AntiAtc;

import android.app.Application;
import android.content.Context;

import dji.sdk.base.BaseProduct;
import dji.sdk.flightcontroller.FlightController;
import dji.sdk.mission.waypoint.WaypointMissionOperator;
import dji.sdk.products.Aircraft;
import dji.sdk.sdkmanager.DJISDKManager;

public class GetProductApplication extends Application {
    public static final String FLAG_GET_PRODUCT = "get_product";
    public static final String FLAG_CONNECTION_CHANGE = "dji_sdk_connection_change";
    private static BaseProduct mProduct;
    private static FlightController mFlightController;
//    private static Gimbal mGimbal;
    private Application instance;

    private static WaypointMissionOperator WNOinstance;

    public void setContext(Application application) {
        instance = application;
    }

    @Override
    public Context getApplicationContext() {
        return instance;
    }

    public GetProductApplication() {

    }

    /**
     * This function is used to get the instance of DJIBaseProduct.
     * If no product is connected, it returns null.
     */
    public static synchronized BaseProduct getProductInstance() {
        if (null == mProduct) {
            mProduct = DJISDKManager.getInstance().getProduct();
        }
        return mProduct;
    }


    public static synchronized FlightController getFlightControllerInstance() {

        if (getProductInstance() == null) return null;

        mFlightController = ((Aircraft) getProductInstance()).getFlightController();

        return mFlightController;
    }

//    public static synchronized Gimbal getGimbal() {
//
//        if (getProductInstance() == null) return null;
//
//        mGimbal = ((Gimbal) getProductInstance()).;
//
//        return mGimbal;
//    }

    public static synchronized WaypointMissionOperator getWaypointMissionOperator() {
        if (WNOinstance == null) {
            WNOinstance = DJISDKManager.getInstance().getMissionControl().getWaypointMissionOperator();
        }
        return WNOinstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }

}
